package jp.co.sharp.android.parents.kidsguard.activity.setting.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

import jp.co.sharp.android.parents.kidsguard.R;
import jp.co.sharp.android.parents.kidsguard.activity.setting.ContactOptActivity;
import jp.co.sharp.android.parents.kidsguard.activity.setting.PersonalAlarmSettingActivity;
import jp.co.sharp.android.parents.kidsguard.dto.ContactListsDto;

public class PersonalAlarmSettingItemAdaptor extends ArrayAdapter<ContactListsDto> {
    private  int resourceId;
    private OnClickItemListenter onClickItemListenter;
    private Context mContext;


    public PersonalAlarmSettingItemAdaptor(@NonNull Context context, int resource) {
        super(context, resource);
    }

    public PersonalAlarmSettingItemAdaptor(@NonNull Context context, int resource, int textViewResourceId) {
        super(context, resource, textViewResourceId);
    }

    public PersonalAlarmSettingItemAdaptor(@NonNull Context context, int resource, @NonNull ContactListsDto[] objects) {
        super(context, resource, objects);
    }

    public PersonalAlarmSettingItemAdaptor(@NonNull Context context, int resource, int textViewResourceId, @NonNull ContactListsDto[] objects) {
        super(context, resource, textViewResourceId, objects);
    }

    public PersonalAlarmSettingItemAdaptor(@NonNull Context context, int resource, @NonNull List<ContactListsDto> objects,OnClickItemListenter onClickItemListenter) {
        super(context, resource, objects);
        this.resourceId = resource;
        this.onClickItemListenter=onClickItemListenter;
        this.mContext = context;
    }

    public PersonalAlarmSettingItemAdaptor(@NonNull Context context, int resource,  @NonNull List<ContactListsDto> objects) {
        super(context, resource, objects);
        this.resourceId = resource;
        this.mContext = context;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent) {
        ContactListsDto contactListsDto = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (null == converView) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
            viewHolder = new ViewHolder();

            viewHolder.contact =view.findViewById(R.id.contact);
            viewHolder.contactName =view.findViewById(R.id.contactName);
            view.setTag(viewHolder);

        }else {
            view = converView;
            viewHolder = (ViewHolder)view.getTag();
        }
        viewHolder.contact.setText("発信先"+(position+1));
        viewHolder.contactName.setText(contactListsDto.getName());
        if(contactListsDto.getName()==null){
            viewHolder.contactName.setText("おとうさん");
        }

//        viewHolder.contact.setTextColor(Color.parseColor("#4D575FD4"));


        viewHolder.contact.setOnClickListener(new ContactClick());
        viewHolder.contact.setTag(position);
        return view;
    }

    class ViewHolder{
        TextView contact;
        TextView contactName;
    }

    public interface OnClickItemListenter {
        void chooseItemClick(int position);
    }

    class ContactClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mContext, ContactOptActivity.class);
            intent.putExtra("position",(Integer)v.getTag());
            int ContactOptRequestCode=100;
            PersonalAlarmSettingActivity.mPageJumpFlag = true;
            ((Activity) mContext).startActivityForResult(intent, ContactOptRequestCode);
        }
    }
}







































































